//
//  PTCoreObject.m
//  PlanTech
//
//  Created by ruifeng song on 2018/7/16.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTCoreObject.h"
#import "PTCoreDefine.h"

@implementation PTMJsonResult

+(NSError *)checkWithResult:(PTMJsonResult *)result
{
    if(!result) {
#ifdef DEBUG
        NSDictionary * userInfo = @{NSLocalizedDescriptionKey : @"没有返回JsonResult"};
#else
        NSDictionary * userInfo = @{NSLocalizedDescriptionKey : kPTCore_Prompt_Network_Error};
#endif
        return [NSError errorWithDomain:kPTCoreErrorDomain code:kPTCore_Error_Unknown userInfo:userInfo];
    }
    
    if(1000 != [result.code integerValue]) {
#ifdef DEBUG
        NSLog(@"Server Error Code = %@ Message = %@", result.code, result.message);
#endif
        NSDictionary * userInfo = @{NSLocalizedDescriptionKey : result.message?:@""};
        return [NSError errorWithDomain:kPTCoreErrorDomain
                                   code:[result.code integerValue]
                               userInfo:userInfo];
    }
    
    return nil;
}

+(NSError *)checkWithHTTPError:(NSError *)error
{
    if(nil != error) {
#ifdef DEBUG
        NSDictionary * userInfo = @{NSLocalizedDescriptionKey: error.localizedDescription};
#else
        NSDictionary * userInfo = @{NSLocalizedDescriptionKey: kPTCore_Prompt_Network_Error};
#endif
        return [NSError errorWithDomain:kPTCoreErrorDomain code:kPTCore_Error_Unknown userInfo:userInfo];
    }
    return nil;
}

@end

